package com.paic.tpa;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.Date;
import java.util.Map;

import org.apache.commons.io.IOUtils;

@Controller
@RequestMapping("/menus")
public class MenuController {
	
	static {
		System.out.println("MenuController is loaded...");
	}
	
	@Autowired
	private MenuService menuService;
	
	@Value("I love you!")
	private String normal;
	
	@Value("#{systemProperties['os.name']}")
	private String osName;
	
	@Value("${server.port}")
	private String fromProperties;
	
	@Value("http://spring.io")
	private Resource testUrl;
	
	@RequestMapping(value="/index")
	public String index() {
//		model.put("time", new Date());
//	    model.put("message", "JimmyMo");
	    return "another";
	}
	
	@RequestMapping(value="/val")
	public String value() {
		try {
			return IOUtils.toString(testUrl.getInputStream());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "done";
	}
	
	@RequestMapping(value = "/{roles}", method = RequestMethod.GET)
	@ResponseBody
    public String sayWorld(@PathVariable("roles") String roles) {
//        return "Hello2 " + name;
		return menuService.getMenus(roles);
    }
}
